Split function into realized and unrealized variants, and consolidate the
authorJonathan Blandford <jrb@gnome.org>
Wed, 3 Mar 2004 04:52:01 +0000 (04:52 +0000)
committerJonathan Blandford <jrb@src.gnome.org>
Wed, 3 Mar 2004 04:52:01 +0000 (04:52 +0000)
Tue Mar  2 23:39:55 2004  Jonathan Blandford  <jrb@gnome.org>

        * gtk/gtkfilechooserdialog.c
        (file_chooser_widget_default_realized_size_changed): Split
        function into realized and unrealized variants, and consolidate
        the handling fo size-changing and default changing.

        * gtk/gtkfilechooserembed.[ch] (gtk_file_chooser_embed_class_init):
        remove resizable-hints-changed, as it just complicated things.

        * gtk/gtkfilechooserdefault.c (update_appearance): Don't emit
        resizable-hints-changed.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkfilechooserdefault.c
gtk/gtkfilechooserdialog.c
gtk/gtkfilechooserembed.c
gtk/gtkfilechooserembed.h
tests/testfilechooser.c

index 16aab9aad23853d54416434561476ec2de4ef5e1..9999bbafceaea4a80c137aae9fa6c8c01a3e552b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+Tue Mar  2 23:39:55 2004  Jonathan Blandford  <jrb@gnome.org>
+
+       * gtk/gtkfilechooserdialog.c
+       (file_chooser_widget_default_realized_size_changed): Split
+       function into realized and unrealized variants, and consolidate
+       the handling fo size-changing and default changing.
+
+       * gtk/gtkfilechooserembed.[ch] (gtk_file_chooser_embed_class_init):
+       remove resizable-hints-changed, as it just complicated things.
+
+       * gtk/gtkfilechooserdefault.c (update_appearance): Don't emit
+       resizable-hints-changed.
+       
 2004-03-03  Tor Lillqvist  <tml@iki.fi>
 
        * gtk/gtk.def: Add a missing entry. (#135982, J. Ali Harlow)
index 16aab9aad23853d54416434561476ec2de4ef5e1..9999bbafceaea4a80c137aae9fa6c8c01a3e552b 100644 (file)
@@ -1,3 +1,16 @@
+Tue Mar  2 23:39:55 2004  Jonathan Blandford  <jrb@gnome.org>
+
+       * gtk/gtkfilechooserdialog.c
+       (file_chooser_widget_default_realized_size_changed): Split
+       function into realized and unrealized variants, and consolidate
+       the handling fo size-changing and default changing.
+
+       * gtk/gtkfilechooserembed.[ch] (gtk_file_chooser_embed_class_init):
+       remove resizable-hints-changed, as it just complicated things.
+
+       * gtk/gtkfilechooserdefault.c (update_appearance): Don't emit
+       resizable-hints-changed.
+       
 2004-03-03  Tor Lillqvist  <tml@iki.fi>
 
        * gtk/gtk.def: Add a missing entry. (#135982, J. Ali Harlow)
index 16aab9aad23853d54416434561476ec2de4ef5e1..9999bbafceaea4a80c137aae9fa6c8c01a3e552b 100644 (file)
@@ -1,3 +1,16 @@
+Tue Mar  2 23:39:55 2004  Jonathan Blandford  <jrb@gnome.org>
+
+       * gtk/gtkfilechooserdialog.c
+       (file_chooser_widget_default_realized_size_changed): Split
+       function into realized and unrealized variants, and consolidate
+       the handling fo size-changing and default changing.
+
+       * gtk/gtkfilechooserembed.[ch] (gtk_file_chooser_embed_class_init):
+       remove resizable-hints-changed, as it just complicated things.
+
+       * gtk/gtkfilechooserdefault.c (update_appearance): Don't emit
+       resizable-hints-changed.
+       
 2004-03-03  Tor Lillqvist  <tml@iki.fi>
 
        * gtk/gtk.def: Add a missing entry. (#135982, J. Ali Harlow)
index 16aab9aad23853d54416434561476ec2de4ef5e1..9999bbafceaea4a80c137aae9fa6c8c01a3e552b 100644 (file)
@@ -1,3 +1,16 @@
+Tue Mar  2 23:39:55 2004  Jonathan Blandford  <jrb@gnome.org>
+
+       * gtk/gtkfilechooserdialog.c
+       (file_chooser_widget_default_realized_size_changed): Split
+       function into realized and unrealized variants, and consolidate
+       the handling fo size-changing and default changing.
+
+       * gtk/gtkfilechooserembed.[ch] (gtk_file_chooser_embed_class_init):
+       remove resizable-hints-changed, as it just complicated things.
+
+       * gtk/gtkfilechooserdefault.c (update_appearance): Don't emit
+       resizable-hints-changed.
+       
 2004-03-03  Tor Lillqvist  <tml@iki.fi>
 
        * gtk/gtk.def: Add a missing entry. (#135982, J. Ali Harlow)
index 16aab9aad23853d54416434561476ec2de4ef5e1..9999bbafceaea4a80c137aae9fa6c8c01a3e552b 100644 (file)
@@ -1,3 +1,16 @@
+Tue Mar  2 23:39:55 2004  Jonathan Blandford  <jrb@gnome.org>
+
+       * gtk/gtkfilechooserdialog.c
+       (file_chooser_widget_default_realized_size_changed): Split
+       function into realized and unrealized variants, and consolidate
+       the handling fo size-changing and default changing.
+
+       * gtk/gtkfilechooserembed.[ch] (gtk_file_chooser_embed_class_init):
+       remove resizable-hints-changed, as it just complicated things.
+
+       * gtk/gtkfilechooserdefault.c (update_appearance): Don't emit
+       resizable-hints-changed.
+       
 2004-03-03  Tor Lillqvist  <tml@iki.fi>
 
        * gtk/gtk.def: Add a missing entry. (#135982, J. Ali Harlow)
index ca0d7c1c1f5c849c749e612d096e9f02dc3a4f22..8502230202b869fd42c245694015c9ee8b20eeb1 100644 (file)
@@ -2384,7 +2384,6 @@ update_appearance (GtkFileChooserDefault *impl)
     }
 
   g_signal_emit_by_name (impl, "default-size-changed");
-  g_signal_emit_by_name (impl, "resizable-hints-changed");
 }
 
 static void
index 8ba2804adb5a8899d5ffe63ce8a292c9c36927f9..4aa02b93ee8cee3604d61577244639ac7e1810da 100644 (file)
@@ -36,6 +36,8 @@ struct _GtkFileChooserDialogPrivate
   /* for use with GtkFileChooserEmbed */
   gint default_width;
   gint default_height;
+  gboolean resize_horizontally;
+  gboolean resize_vertically;
 };
 
 #define GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE(o)  (GTK_FILE_CHOOSER_DIALOG (o)->priv)
@@ -127,6 +129,8 @@ gtk_file_chooser_dialog_init (GtkFileChooserDialog *dialog)
   dialog->priv = priv;
   dialog->priv->default_width = -1;
   dialog->priv->default_height = -1;
+  dialog->priv->resize_horizontally = TRUE;
+  dialog->priv->resize_vertically = TRUE;
 
   gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
 }
@@ -150,25 +154,17 @@ file_chooser_widget_file_activated (GtkFileChooser       *chooser,
 }
 
 static void
-file_chooser_widget_resizable_hints_changed (GtkWidget            *widget,
-                                            GtkFileChooserDialog *dialog)
+file_chooser_widget_update_hints (GtkFileChooserDialog *dialog)
 {
   GtkFileChooserDialogPrivate *priv;
-  gboolean resize_horizontally;
-  gboolean resize_vertically;
   GdkGeometry geometry;
 
   priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog);
 
-  _gtk_file_chooser_embed_get_resizable_hints (GTK_FILE_CHOOSER_EMBED (priv->widget),
-                                              &resize_horizontally,
-                                              &resize_vertically);
-
-
   geometry.min_width = -1;
   geometry.min_height = -1;
-  geometry.max_width = (resize_horizontally?G_MAXSHORT:-1);
-  geometry.max_height = (resize_vertically?G_MAXSHORT:-1);
+  geometry.max_width = (priv->resize_horizontally?G_MAXSHORT:-1);
+  geometry.max_height = (priv->resize_vertically?G_MAXSHORT:-1);
 
   gtk_window_set_geometry_hints (GTK_WINDOW (dialog), NULL,
                                 &geometry,
@@ -176,66 +172,131 @@ file_chooser_widget_resizable_hints_changed (GtkWidget            *widget,
 }
 
 static void
-file_chooser_widget_default_size_changed (GtkWidget            *widget,
-                                         GtkFileChooserDialog *dialog)
+file_chooser_widget_default_realized_size_changed (GtkWidget            *widget,
+                                                  GtkFileChooserDialog *dialog)
 {
   GtkFileChooserDialogPrivate *priv;
-  gint extra_width;
-  gint extra_height;
-  gint width, height;
+  gint width;
+  gint height;
+  gint default_width, default_height;
   GtkRequisition req;
   gboolean resize_horizontally;
   gboolean resize_vertically;
+  gboolean update_hints;
+  gint dx = 0, dy = 0;
+  gint cur_width, cur_height;
 
   priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog);
 
   /* Force a size request of everything before we start.  This will make sure
    * that widget->requisition is meaningful. */
   gtk_widget_size_request (GTK_WIDGET (dialog), &req);
-
-  /* Determine how much space the rest of the dialog uses compared to priv->widget */
-  extra_width = GTK_WIDGET (dialog)->requisition.width - priv->widget->requisition.width;
-  extra_height = GTK_WIDGET (dialog)->requisition.height - priv->widget->requisition.height;
-
+  gtk_window_get_size (GTK_WINDOW (dialog), &cur_width, &cur_height);
+  width = GTK_WIDGET (dialog)->requisition.width - priv->widget->requisition.width;
+  height = GTK_WIDGET (dialog)->requisition.height - priv->widget->requisition.height;
   _gtk_file_chooser_embed_get_default_size (GTK_FILE_CHOOSER_EMBED (priv->widget),
-                                           &width, &height);
+                                           &default_width, &default_height);
 
-  width = extra_width + width;
-  height = extra_height + height;
+  /* Ideal target size modulo any resizing */
+  width = default_width + width;
+  height = default_height + height;
 
-  /* FIXME: We should make sure that we arent' bigger than the current screen */
-  if (GTK_WIDGET_REALIZED (dialog) &&
-      priv->default_width > 0 &&
-      priv->default_height > 0)
+  /* Now, we test for resizability */
+  update_hints = FALSE;
+  _gtk_file_chooser_embed_get_resizable_hints (GTK_FILE_CHOOSER_EMBED (priv->widget),
+                                              &resize_horizontally,
+                                              &resize_vertically);
+  resize_vertically = (!! resize_vertically);     /* normalize */
+  resize_horizontally = (!! resize_horizontally);
+
+  if (resize_horizontally && priv->resize_horizontally)
+    {
+      dx = default_width - priv->default_width;
+      priv->default_width = default_width;
+    }
+  else if (resize_horizontally && ! priv->resize_horizontally)
+    {
+      /* We restore to the ideal size + any change in default_size (which is not
+       * expected).  It would be nicer to store the older size to restore to in
+       * the future. */
+      dx = default_width - priv->default_width;
+      dx += width - cur_width;
+      priv->default_width = default_width;
+      update_hints = TRUE;
+    }
+  else
+    {
+      update_hints = TRUE;
+    }
+  
+  if (resize_vertically && priv->resize_vertically)
+    {
+      dy = default_height - priv->default_height;
+      priv->default_height = default_height;
+    }
+  else if (resize_vertically && ! priv->resize_vertically)
+    {
+      dy = default_height - priv->default_height;
+      dy += height - cur_height;
+      priv->default_height = default_height;
+      update_hints = TRUE;
+    }
+  else
     {
-      gint cur_width, cur_height;
-      gint dx, dy;
+      update_hints = TRUE;
+    }
 
-      gtk_window_get_size (GTK_WINDOW (dialog), &cur_width, &cur_height);
+  priv->resize_horizontally = resize_horizontally;
+  priv->resize_vertically = resize_vertically;
 
-      dx = width - priv->default_width;
-      dy = height - priv->default_height;
+  /* FIXME: We should make sure that we arent' bigger than the current screen */
+  if (dx != 0 || dy != 0)
+    {
       gtk_window_resize (GTK_WINDOW (dialog),
                         cur_width + dx,
                         cur_height + dy);
     }
-  else
-    {
-      gtk_window_resize (GTK_WINDOW (dialog), width, height);
-    }
-
-  _gtk_file_chooser_embed_get_resizable_hints (GTK_FILE_CHOOSER_EMBED (priv->widget),
-                                              &resize_horizontally,
-                                              &resize_vertically);
 
   /* Only store the size if we can resize in that direction. */
-  if (resize_horizontally)
-    priv->default_width = width;
-  if (resize_vertically)
-    priv->default_height = height;
+  if (update_hints)
+    file_chooser_widget_update_hints (dialog);
 }
 
+static void
+file_chooser_widget_default_unrealized_size_changed (GtkWidget            *widget,
+                                                    GtkFileChooserDialog *dialog)
+{
+  GtkFileChooserDialogPrivate *priv;
+  GtkRequisition req;
+  gint width, height;
+
+  priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog);
+  gtk_widget_size_request (GTK_WIDGET (dialog), &req);
+
+  _gtk_file_chooser_embed_get_resizable_hints (GTK_FILE_CHOOSER_EMBED (priv->widget),
+                                              &(priv->resize_horizontally),
+                                              &(priv->resize_vertically));
+  _gtk_file_chooser_embed_get_default_size (GTK_FILE_CHOOSER_EMBED (priv->widget),
+                                           &(priv->default_width), &(priv->default_height));
+  
+  /* Determine how much space the rest of the dialog uses compared to priv->widget */
+  width = priv->default_width + GTK_WIDGET (dialog)->requisition.width - priv->widget->requisition.width;
+  height = priv->default_height + GTK_WIDGET (dialog)->requisition.height - priv->widget->requisition.height;
+
+  gtk_window_set_default_size (GTK_WINDOW (dialog), width, height);
+  file_chooser_widget_update_hints (dialog);
+}
 
+static void
+file_chooser_widget_default_size_changed (GtkWidget            *widget,
+                                         GtkFileChooserDialog *dialog)
+{
+  if (GTK_WIDGET_REALIZED (dialog))
+    file_chooser_widget_default_realized_size_changed (widget, dialog);
+  else
+    file_chooser_widget_default_unrealized_size_changed (widget, dialog);
+}
+  
 static GObject*
 gtk_file_chooser_dialog_constructor (GType                  type,
                                     guint                  n_construct_properties,
@@ -262,8 +323,6 @@ gtk_file_chooser_dialog_constructor (GType                  type,
                    G_CALLBACK (file_chooser_widget_file_activated), object);
   g_signal_connect (priv->widget, "default-size-changed",
                    G_CALLBACK (file_chooser_widget_default_size_changed), object);
-  g_signal_connect (priv->widget, "resizable-hints-changed",
-                   G_CALLBACK (file_chooser_widget_resizable_hints_changed), object);
 
   gtk_box_pack_start (GTK_BOX (GTK_DIALOG (object)->vbox), priv->widget, TRUE, TRUE, 0);
   gtk_widget_show (priv->widget);
index 72072408b5d97c1eb3602c31cab1da27a22f4413..61a48fff567f39853c6850550eff0010d681613c 100644 (file)
@@ -10,8 +10,6 @@ static void delegate_get_resizable_hints      (GtkFileChooserEmbed *chooser_embe
                                               gboolean            *resize_vertically);
 static void delegate_default_size_changed     (GtkFileChooserEmbed *chooser_embed,
                                               gpointer             data);
-static void delegate_resizable_hints_changed  (GtkFileChooserEmbed *chooser_embed,
-                                              gpointer             data);
 
 static GtkFileChooserEmbed *
 get_delegate (GtkFileChooserEmbed *receiver)
@@ -56,8 +54,6 @@ _gtk_file_chooser_embed_set_delegate (GtkFileChooserEmbed *receiver,
 
   g_signal_connect (delegate, "default_size_changed",
                    G_CALLBACK (delegate_default_size_changed), receiver);
-  g_signal_connect (delegate, "resizable_hints_changed",
-                   G_CALLBACK (delegate_resizable_hints_changed), receiver);
 }
 
 
@@ -85,13 +81,6 @@ delegate_default_size_changed (GtkFileChooserEmbed *chooser_embed,
   g_signal_emit_by_name (data, "default-size-changed");
 }
 
-static void
-delegate_resizable_hints_changed (GtkFileChooserEmbed *chooser_embed,
-                                 gpointer             data)
-{
-  g_signal_emit_by_name (data, "resizable-hints-changed");
-}
-
 
 /* publicly callable functions */
 
@@ -132,13 +121,6 @@ gtk_file_chooser_embed_class_init (gpointer g_iface)
                NULL, NULL,
                _gtk_marshal_VOID__VOID,
                G_TYPE_NONE, 0);
-  g_signal_new ("resizable-hints-changed",
-               iface_type,
-               G_SIGNAL_RUN_LAST,
-               G_STRUCT_OFFSET (GtkFileChooserEmbedIface, resizable_hints_changed),
-               NULL, NULL,
-               _gtk_marshal_VOID__VOID,
-               G_TYPE_NONE, 0);
 }
 
 void
index a44f72b20d78f48aaa1d894f0bbe7bd3495ee0cf..e41c7f86ccd19a0f868c6879b5ba89fd095aa8e7 100644 (file)
@@ -49,7 +49,6 @@ struct _GtkFileChooserEmbedIface
   /* Signals
    */
   void (*default_size_changed)    (GtkFileChooserEmbed *chooser_embed);
-  void (*resizable_hints_changed) (GtkFileChooserEmbed *chooser_embed);
 };
 
 GType _gtk_file_chooser_embed_get_type (void);
index d6f0a1cfb7d66f0ef6c932a7b7b1cb78266c2c8f..6e43ac8b12b85f1fdc90937547c2745e30550b4a 100644 (file)
@@ -356,7 +356,7 @@ main (int argc, char **argv)
 
   dialog = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG,
                         "action", action,
-                        "file-system-backend", "gnome-vfs",
+                        "file-system-backend", "gtk+",
                         NULL);
   switch (action)
     {